package com.horsen.service.edu.controller.web;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.horsen.common.util.R;
import com.horsen.service.edu.controller.BaseController;
import com.horsen.service.edu.model.Teacher;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 讲师 前端控制器
 *
 * @author Horsen
 */
@Api(tags = "讲师管理")
@ApiSupport(order = 1)
@RestController("WebTeacher")
@RequestMapping("/web/edu/teachers")
public class TeacherController extends BaseController {


    @ApiOperationSupport(order = 1)
    @ApiOperation("获取所有讲师")
    @Cacheable(key = "'webQueryAllTeachers'", value = "teacherList")
    @GetMapping("/")
    public R queryAll() {
        List<Teacher> list = teacherService.list();
        return list != null && list.size() != 0 ?
                R.ok("获取所有讲师成功").setData("items", list) : R.error("获取所有讲师失败");
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation("根据ID获取一个讲师")
    @GetMapping("/{id}")
    public R queryById(@ApiParam(value = "讲师对象", required = true)
                       @PathVariable String id) {
        Map<String, Object> map = teacherService.queryInfoById(id);
        return map != null ?
                R.ok("获取ID=" + id + "的讲师详情成功").setData(map) : R.error("获取ID=" + id + "的讲师详情失败");
    }
}

